#ifndef REDUCTION_OPERATORS_H
#define REDUCTION_OPERATORS_H

///
//! Arg Max
//! @input A,B
//! @output the index-value pair which value is bigger
///
__device__ static void argMax(
					int mapAIndex, float mapAValue, //input A (index, value)
					int mapBIndex, float mapBValue, //input B (index,value)
					int* reduceIndex, float* reduceValue) { //output (index,value)
	if (mapBValue > mapAValue) {
		*reduceIndex = mapBIndex;
		*reduceValue = mapBValue;
	} else {
		*reduceIndex = mapAIndex;
		*reduceValue = mapAValue;
	}
}

///
//! Arg Min
//! @input A,B
//! @output the index-value pair which value is smaller
///
__device__ static void argMin(
					int mapAIndex, float mapAValue, //input A (index, value)
					int mapBIndex, float mapBValue, //input B (index, value)
					int* reduceIndex, float* reduceValue) { //output (index,value)
	if (mapBValue < mapAValue) {
		*reduceIndex = mapBIndex;
		*reduceValue = mapBValue;
	} else {
		*reduceIndex = mapAIndex;
		*reduceValue = mapAValue;
	}
}

///
//! max() operator
//! @input a,b
//! @output result
///
template<typename T>
__device__ void maxOperator(T a, T b, T* result) {
  *result = (a < b) ? b : a;
}

#endif
